'use strict'

const { DataTypes, Model, Op } = require('../../../azeroth').sequelize;
class Flaw_2 extends Model { }

const initFlawData_2 = (sequelize_aim) => {
    Flaw_2.init(
        {
            uid: {
                autoIncrement: true,
                type: DataTypes.INTEGER,
                allowNull: false,
                primaryKey: true
            },
            job_id: {
                type: DataTypes.INTEGER,
                allowNull: false,
                defaultValue: 0,
                primaryKey: true
            },
            sheet_id: {
                type: DataTypes.INTEGER,
                allowNull: false,
                defaultValue: 0,
                primaryKey: true
            },
            sheet_id_seq: {
                type: DataTypes.INTEGER,
                allowNull: true
            },
            camera_id: {
                type: DataTypes.INTEGER,
                allowNull: true
            },
            class_id: {
                type: DataTypes.INTEGER,
                allowNull: true
            },
            center_pos_md: {
                type: DataTypes.DOUBLE(64, 2),
                allowNull: true
            },
            center_pos_cd: {
                type: DataTypes.DOUBLE(64, 2),
                allowNull: true
            },
            length_md: {
                type: DataTypes.DOUBLE(64, 2),
                allowNull: true
            },
            length_cd: {
                type: DataTypes.DOUBLE(64, 2),
                allowNull: true
            },
            gen_time: {
                type: DataTypes.BIGINT,
                allowNull: true
            },
            gen_time_str: {
                type: DataTypes.STRING(64),
                allowNull: true
            },
            flaw_id_in_sheet: {
                type: DataTypes.INTEGER,
                allowNull: true
            },
            save_path: {
                type: DataTypes.STRING(256),
                allowNull: true
            },
            ui_show_text: {
                type: DataTypes.STRING(16),
                allowNull: true
            }
        },
        {
            freezeTableName: true,
            sequelize: sequelize_aim,
            modelName: 'flaw',
            timestamps: false
        }
    )
}

Flaw_2.getMaxUid = async (sequelize_aim) => {
    let res = await sequelize_aim.query(`select max(uid) as uid from flaw`, { type: sequelize_aim.QueryTypes.SELECT });
    if (res.length) {
        return res[0].uid;
    } else {
        return 0;
    }
}

Flaw_2.upload = async (data) => {
    let res = await Flaw_2.bulkCreate(data, { updateOnDuplicate: ['uid'] });
    return res;
}

module.exports = {
    Flaw_2,
    initFlawData_2
};